using System.Threading.Tasks;
using HZY.Logic.Sys;
using Microsoft.AspNetCore.Http;

namespace HZY.Admin.Core
{
    public class HZYAppMiddleware : IMiddleware
    {
        protected AccountLogic logic { get; }

        public HZYAppMiddleware(AccountLogic _logic)
        {
            this.logic = _logic;
        }

        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            context.Request.EnableBuffering();//启用倒带功能，就可以让 Request.Body 可以再次读取
            await logic.InsertAppLogAsync();
            context.Request.Body.Position = 0;//必须存在

            await next.Invoke(context);
        }
    }
}